<?php namespace Admin\Controller; 
//测试控制器
class IndexController extends CommonController{

	//构造函数
	public function __auto()
	{

	}
	
    //动作
    public function index(){
       View::make();
    }
    public function welcome(){
    	View::make();
    }
    public function changPassword(){
    	//先验证新密码长度和确认密码
    	if(IS_POST){
	    	$newPassword=Q('post.newPassword');
	    	if(strlen("$newPassword")<6) View::error("新密码长度少于6位");

	    	$confirmPassword=Q('post.confirmPassword');
	    	if($confirmPassword != $newPassword) View::error("两次密码输入不一致");

	    	$aid=$_SESSION['info']['aid'];
	    	$data=Db::table('admin')->where("aid='{$aid}'")->get();

	    	$oldPassword=Q('post.oldPassword','',"md5");
	    	// $data=Db::table('admin')->where("password='{$oldPassword}'")->get();
	    	// if(!$data) View::error("原密码输入错误");
	    	if($oldPassword != $data[0]['password']) View::error("原密码输入错误");
	    	
	    	 Db::table('admin')->where("aid={$aid}")->update(['password'=>md5($newPassword)]);
	    	 View::success('修改密码成功',U('Login/out'));
	    	// exit;
    	}
    	View::make();
    }
    // 上传文件
    public function upload()
	{
	    $file = Upload::path('Upload/Content/' . date('y/m'))->make();
	    if (empty($file)) {
	        // 相当于：echo json_encode(Upload::getError());exit;
	        $this->ajax(Upload::getError());
	    } else {
	        /** $file内部就是以下这个数组
	            $file = array(
	                0 => array(
		                'path' => 'Upload/Content/15/8/123981239172.jpg'    ,
		                'url' => 'http://localhost/cms_edu/Upload/Content/15/8/123981239172.jpg',
		                'image' => 1
	            ),
	        );**/
	        //上传成功，把上传好的信息返给js 也就是uploadify
	        $data = $file[0];
	        // 相当于：echo json_encode($data);exit;
	        $this->ajax($data);
	    }
	}
}
